package com.itbaima.controller.HRMM;

import com.itbaima.pojo.entity.Department;
import com.itbaima.result.Result;
import com.itbaima.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
@Slf4j
public class DepartmentController {


    @Autowired
    private DepartmentService departmentService ;

    @GetMapping
    public Result<List<Department>> selectLevel3dp(){

        log.info("正在查询三级部门");
        List<Department> departmentList = departmentService.selectLevel3dp();
        return Result.success(departmentList);
    }


    /**
     * 依次查询上级部门信息       暂时弃置！！！！
     * @param department1
     * @return
     */
    @PostMapping
    public Result<List<Department>> selectUpDp(@RequestBody Department department1){

        Integer parentLevel = department1.getLevel()-1;

        log.info("正在查询{}级部门 ， {} " , parentLevel,department1);

        List<Department> departmentList = departmentService.selectLevelUpDp(department1);

        return Result.success(departmentList);

    }


    @PostMapping("/level2")
    public Result<Department> selectLevel2Dp(@RequestBody Department department3){

        log.info("查询相应三级部门的二级部门：{}" , department3);

        Department department2 = departmentService.selectLevel2dp(department3);
        return Result.success(department2);
    }

    @PostMapping("/level3")
    public Result<Department> selectLevel1Dp(@RequestBody Department department3){

        log.info("查询相应二级部门的一级部门：{}" , department3);

        Department department1 = departmentService.selectLevel1dp(department3);

        return Result.success(department1);

    }


    @DeleteMapping("/{id}")
    public Result deleteDP(@PathVariable("id") Integer id){

        log.info("开始进行人力资源档案删除：{}" , id);

        departmentService.delete(id);

        return Result.success();
    }

}
